﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfClient
{
    public static class Logger
    {
        private static StreamWriter _outputStream;

        

        static Logger()
        {
            try
            {
                _outputStream = new StreamWriter("logs.txt", true);
            }
            catch
            {
                // Log disabled
            }
            
        }

        public static void Exception(string message, Exception e)
        {
            if (_outputStream == null)
            {
                return;
            }
            var sb = new StringBuilder();

            sb.AppendLine(string.Format("{0} : {1}", DateTime.Now.ToString(), message));
            sb.AppendLine(string.Format("Exception : {0}, Message : {1}", e.GetType().FullName, e.Message));
            sb.AppendLine(string.Format("Trace : {0}", e.StackTrace));
            sb.AppendLine("");
            _outputStream.Write(sb.ToString());
            _outputStream.Flush();

        }
    }
}
